package com.cq.androidtools.recycleview

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.cq.androidtools.R

class MyAdapter : BaseAdapter {

    private var list = mutableListOf<String>()
    private var context : Context? = null

    constructor(list: MutableList<String>, context: Context?) : super() {
        this.list = list
        this.context = context
    }


    override fun getCount(): Int {
        return list.size
    }

    override fun getItem(p0: Int): Any {
        return list[p0]
    }

    override fun getItemId(p0: Int): Long {
       return p0.toLong()
    }

    override fun getView(p0: Int, p1: View?, p2: ViewGroup?): View {
        val holder : ViewH
        var view = p1
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_text, p2,false) as View
            holder = ViewH()
            holder.textv = view.findViewById(R.id.item_grid_text) as TextView
            view.tag = holder
        } else {
            holder = view.tag as ViewH
        }
        holder.textv!!.text = list[p0]
        return view
    }

    class ViewH {
        var textv : TextView? = null
    }
}